import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import NotFound from '../views/NotFound.vue'

Vue.use(VueRouter)

const routes = [  //路由（页面之间的跳转）
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: "首页",
    }
  },
  {
    path: '/companyhome',
    name: 'companyhome',
    component: () => import('../views/CompanyHome.vue'), //路由懒加载
    meta: {
      title: "首页",
    },
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('../views/User.vue'), //路由懒加载
    meta: {
      title: "用户登录注册"
    },
  },
  {
    path: '/company',
    name: 'company',
    component: () => import('../views/Company.vue'), //路由懒加载
    meta: {
      title: "企业登录注册"
    },
  },
  {
    path: '/admin',
    name: 'admin',
    component: () => import('../views/Admin.vue'), //路由懒加载
    meta: {
      title: "管理员登录"
    },
  },
  {
    path: '/list',
    name: 'list',
    component: () => import('../views/list.vue'), //路由懒加载
    meta: {
      title: "管理员列表",
    },
  },


  {
    path: "/404",
    name: '404',
    component: NotFound,
    meta: {
      title: "404"
    },
  },
  {
    path: "*",
    redirect: "/404",
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//   document.title = to.meta?.title;
//   if (to.meta?.isLogin) {//需要登录
//     let userinfo = window.localStorage.getItem("userinfo");
//     if (userinfo) {
//       next();
//     } else {
//       next("/");
//     }
//   }
//   next();
// })

export default router
